package org.gnyxy.controller.front;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.gnyxy.result.Result;
import org.gnyxy.service.CollectService;
import org.gnyxy.vo.CollectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/front/api/collect")
@Slf4j
@Api(tags = "小程序端-收藏")
public class CollectController {
    @Autowired
    private CollectService collectService;

    /**
     * 添加菜品到收藏
     * @param dishId
     * @return
     */
    @PostMapping("/addDish/{dishId}")
    @ApiOperation("添加菜品到收藏")
    public Result add(@PathVariable Long dishId){
        log.info("添加菜品: {} 到收藏",dishId);
        collectService.add(dishId);
        return Result.success();
    }

    @PostMapping("/addMaterial/{materialId}")
    @ApiOperation("添加食材到收藏")
    public Result addMaterial(@PathVariable Long materialId){
        log.info("添加食材: {}到收藏",materialId);
        collectService.addMaterial(materialId);
        return Result.success();
    }

    /**
     * 删除收藏中的菜品
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    @ApiOperation("删除收藏中的菜品、食材")
    public Result delete(@PathVariable Long id){
        log.info("删除收藏中的菜品、食材: {}",id);
        collectService.delete(id);
        return Result.success();
    }

    /**
     * 查看收藏的所有菜品
     * @return
     */
    @GetMapping("/getAll")
    @ApiOperation("查看收藏的所有菜品、食材")
    public Result getAll(){
        log.info("查看收藏的所有菜品、食材");

        List<CollectVO> collectVOS = collectService.getAll();
        return Result.success(collectVOS);
    }
}
